package dz.salah.ouchenne.com;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import org.apache.ws.policy.AbstractAssertion;
import org.apache.ws.policy.Policy;
import org.apache.ws.policy.PrimitiveAssertion;

public class Requirements {
Vector<Token> Encryption;
Vector<Token> DigitalSignature;
Vector<Token> Protocol;
double ImportanceEncryption;
double ImportanceDigitalSignature;
double ImportanceProtocol;

Requirements(Policy P)
{
this.Encryption= new Vector<Token>();
this.DigitalSignature= new Vector<Token>();
this.Protocol= new Vector<Token>();
List<AbstractAssertion> L=P.getTerms();
L=L.get(0).getTerms(); 
for(int i=0;i<L.size();i++)
{
  List<AbstractAssertion> K=L.get(i).getTerms();
	  for(int j=0;j<K.size();j++)
	   {
		   String s=((PrimitiveAssertion)K.get(j)).getName().toString();
		   s=s.substring(s.lastIndexOf('}')+1, s.length());
		   
		    Hashtable N=((PrimitiveAssertion)K.get(j)).getAttributes();
		    ArrayList list = new ArrayList(N.values());
           
		   
		   if(s.equals("Encryption"))
		  {
		
			   this.ImportanceEncryption= Double.parseDouble((String) list.get(1));
               this.Encryption.add(new Token(((PrimitiveAssertion)K.get(j)).getStrValue(),
            		   Integer.parseInt((String) list.get(0))));
               //System.out.println("Ajout de l'element : ("+((PrimitiveAssertion)K.get(j)).getStrValue()+", "+Integer.parseInt((String) list.get(0))+") dans le Vectuer Encryption. L'importance ="+ this.ImportanceEncryption);  
     		  
		  }  
		  else
		    if(s.equals("DigitalSignature"))
			 {
				
		    	this.ImportanceDigitalSignature= Double.parseDouble((String) list.get(1));
	            this.DigitalSignature.add(new Token(((PrimitiveAssertion)K.get(j)).getStrValue(),
	            		   Integer.parseInt((String) list.get(0))));
	            //System.out.println("Ajout de l'element : ("+((PrimitiveAssertion)K.get(j)).getStrValue()+", "+Integer.parseInt((String) list.get(0))+") dans le Vectuer DigitalSignature. L'importance ="+ this.ImportanceDigitalSignature);
		    	
	     	 }	
			  else
				if(s.equals("Protocol"))
				{
				
					this.ImportanceProtocol= Double.parseDouble((String) list.get(1));
		               this.Protocol.add(new Token(((PrimitiveAssertion)K.get(j)).getStrValue(),
		            		   Integer.parseInt((String) list.get(0))));
		               //System.out.println("Ajout de l'element : ("+((PrimitiveAssertion)K.get(j)).getStrValue()+", "+Integer.parseInt((String) list.get(0))+") dans le Vectuer Protocol. L'importance ="+ this.ImportanceProtocol );	
				}else 
				{System.out.println("Syntax Errors at the Policy File : "+s);System.exit(0);}
					
			
	   }

	   }    
//System.out.println("Done.......!!!!!");
}




Vector<Token> getEncryption()
{
return	this.Encryption;
}

Vector<Token> getDigitalSignature()
{
return	this.DigitalSignature;
}

Vector<Token> getProtocol()
{
return	this.Protocol;
}

}
